import { TargetType } from '@/type';
import { Modal, Form, Input, ModalProps } from 'antd';
export default ({
  initialValues,
  onOk,
  ...props
}: {
  initialValues?: Omit<TargetType, 'flid'>;
  onOk: (values: Omit<TargetType, 'flid'>) => void;
} & Omit<ModalProps, 'onOk'>) => {
  const [form] = Form.useForm();
  const handleOk = async () => {
    const values = await form.validateFields();
    form.resetFields();
    onOk?.(values);
  };
  return (
    <Modal
      title={initialValues ? '编辑' : '新增'}
      {...props}
      onOk={handleOk}
      destroyOnClose
    >
      {props.visible && (
        <Form initialValues={initialValues} form={form}>
          <Form.Item
            label="id"
            name="id"
            rules={[{ required: true, message: '请输入id' }]}
          >
            <Input />
          </Form.Item>
          <Form.Item
            label="分类名称"
            name="name"
            rules={[{ required: true, message: '请输入分类名称' }]}
          >
            <Input />
          </Form.Item>
          <Form.Item label="描述" name="ps">
            <Input />
          </Form.Item>
          <Form.Item label="公式" name="gs">
            <Input />
          </Form.Item>
        </Form>
      )}
    </Modal>
  );
};
